// plugins/icon.client.ts
import { Icon } from '@iconify/vue'

export default defineNuxtPlugin((nuxtApp) => {
  // 注册全局 Icon 组件
  nuxtApp.vueApp.component('Icon', Icon)
  
  // 预加载常用图标集
  const preloadIcons = [
    'mdi:view-dashboard',
    'mdi:clipboard-edit', 
    'mdi:cash-register',
    'mdi:hospital-building',
    'mdi:stethoscope',
    'mdi:play-circle',
    'mdi:white-balance-sunny',
    'mdi:moon-waning-crescent',
    'mdi:theme-light-dark',
    'mdi:cog',
    'mdi:account',
    'mdi:logout',
    'mdi:chevron-down'
  ]
  
  // 异步预加载图标
  if (import.meta.client) {
    import('@iconify/vue').then(({ loadIcons }) => {
      try {
        loadIcons(preloadIcons)
      } catch (error) {
        //console.warn('Failed to preload some icons:', error)
      }
    }).catch(() => {
      //console.warn('Failed to load Iconify')
    })
  }
})
